package org.acghub.mtdb.demo.table;

import com.alibaba.fastjson2.JSONObject;
import org.bson.Document;

/**
* xmlgen自动生成，不要修改此文件！！！
*/
public final class _Tables_ extends org.acghub.mtdb.core.Tables {

	private _Tables_() {
		addTable(test);
		addTable(person);
		addTable(keyvalue);
	}

	public final static _Tables_ INSTANCE = new _Tables_();

	//================================================== table fields start ==================================================
	public Test test = new Test();
	public Person person = new Person();
	public Keyvalue keyvalue = new Keyvalue();
	//================================================== table fields end ==================================================

	public static class Test extends org.acghub.mtdb.core.TTable<Long, org.acghub.mtdb.demo.bean.TestBean> {

		@Override
		public String name() {
			return "test";
		}

		@Override
		public org.acghub.mtdb.demo.bean.TestBean newValue() {
			return new org.acghub.mtdb.demo.bean.TestBean();
		}

		@Override
		public JSONObject marshalJsonKey(Long key) {
			return new JSONObject().fluentPut("_id", key);
		}

		@Override
		public JSONObject marshalJsonValue(org.acghub.mtdb.demo.bean.TestBean value) {
			return value.marshalJson();
		}

		@Override
		public Document marshalDocumentKey(Long key) {
			return new Document("_id", key);
		}

		@Override
		public Document marshalDocumentValue(org.acghub.mtdb.demo.bean.TestBean value) {
			return value.marshalDocument();
		}

		@Override
		public Long unmarshalJsonKey(JSONObject reader) {
			return reader.getLong("_id");
		}

		@Override
		public org.acghub.mtdb.demo.bean.TestBean unmarshalJsonValue(JSONObject reader) {
			org.acghub.mtdb.demo.bean.TestBean v = newValue();
			v.unmarshal(reader);
			return v;
		}

		@Override
		public Long unmarshalDocumentKey(Document reader) {
			return org.acghub.mtdb.common.MarshalUtil.get(reader, "_id", Long.class);
		}

		@Override
		public org.acghub.mtdb.demo.bean.TestBean unmarshalDocumentValue(Document reader) {
			org.acghub.mtdb.demo.bean.TestBean v = newValue();
			v.unmarshal(reader);
			return v;
		}

	}

	static class Person extends org.acghub.mtdb.core.TTable<Long, org.acghub.mtdb.demo.bean.Person> {

		@Override
		public String name() {
			return "person";
		}

		@Override
		public org.acghub.mtdb.demo.bean.Person newValue() {
			return new org.acghub.mtdb.demo.bean.Person();
		}

		@Override
		public JSONObject marshalJsonKey(Long key) {
			return new JSONObject().fluentPut("_id", key);
		}

		@Override
		public JSONObject marshalJsonValue(org.acghub.mtdb.demo.bean.Person value) {
			return value.marshalJson();
		}

		@Override
		public Document marshalDocumentKey(Long key) {
			return new Document("_id", key);
		}

		@Override
		public Document marshalDocumentValue(org.acghub.mtdb.demo.bean.Person value) {
			return value.marshalDocument();
		}

		@Override
		public Long unmarshalJsonKey(JSONObject reader) {
			return reader.getLong("_id");
		}

		@Override
		public org.acghub.mtdb.demo.bean.Person unmarshalJsonValue(JSONObject reader) {
			org.acghub.mtdb.demo.bean.Person v = newValue();
			v.unmarshal(reader);
			return v;
		}

		@Override
		public Long unmarshalDocumentKey(Document reader) {
			return org.acghub.mtdb.common.MarshalUtil.get(reader, "_id", Long.class);
		}

		@Override
		public org.acghub.mtdb.demo.bean.Person unmarshalDocumentValue(Document reader) {
			org.acghub.mtdb.demo.bean.Person v = newValue();
			v.unmarshal(reader);
			return v;
		}

	}

	static class Keyvalue extends org.acghub.mtdb.core.TTable<String, String> {

		@Override
		public String name() {
			return "keyvalue";
		}

		@Override
		public String newValue() {
			return "";
		}

		@Override
		public JSONObject marshalJsonKey(String key) {
			return new JSONObject().fluentPut("_id", key);
		}

		@Override
		public JSONObject marshalJsonValue(String value) {
			return new JSONObject().fluentPut("value", value);
		}

		@Override
		public Document marshalDocumentKey(String key) {
			return new Document("_id", key);
		}

		@Override
		public Document marshalDocumentValue(String value) {
			return new Document("value", value);
		}

		@Override
		public String unmarshalJsonKey(JSONObject reader) {
			return reader.getString("_id");
		}

		@Override
		public String unmarshalJsonValue(JSONObject reader) {
			return reader.getString("value");
		}

		@Override
		public String unmarshalDocumentKey(Document reader) {
			return org.acghub.mtdb.common.MarshalUtil.get(reader, "_id", String.class);
		}

		@Override
		public String unmarshalDocumentValue(Document reader) {
			return org.acghub.mtdb.common.MarshalUtil.get(reader, "value", String.class);
		}

	}

}
